define(function(require){
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");
	
	var Model = function(){
	   
	    this.isLogin = justep.Bind.observable(localStorage.getItem("userInfo")!=null);
	    this.userName = justep.Bind.observable("");
		this.callParent();
	};

	Model.prototype.collectBtnClick = function(event){
		justep.Shell.showPage({url : "$UI/communityOto/mine/houseListActivity.w"});
	};

	Model.prototype.releaseBtnClick = function(event){
		justep.Shell.showPage({url : "$UI/communityOto/mine/houseListActivity.w"});
	};

	Model.prototype.ClickMyInfor = function(event){
		justep.Shell.showPage({url : "$UI/communityOto/mine/myInforActivity.w"});
	};

	Model.prototype.regisBtnClick = function(event){
		justep.Shell.showPage({url : "$UI/communityOto/mine/regisActivity.w"});
	};

	Model.prototype.areaClick = function(event){
		justep.Shell.showPage({url : "$UI/communityOto/mine/areaActivity.w"});
	};

	Model.prototype.loginBtnClick = function(event){
	   
		//this.comp("loginDialog").open();
		this.getParentModel().comp("mineContainer").set("src","$UI/communityOto/mine/login.w");
		this.getParentModel().comp("mineContainer").refresh();
		
	};
	
	 Model.prototype.logined = function(){
		 return this.isLogin.get();
	 };
	

	Model.prototype.loginDialogReceived = function(event){
         //console.log("data",event.data);
         
         if(event.data.action == "login"){
        	 this.isLogin.set(true);
	         var userInfo = JSON.parse(localStorage.getItem("userInfo"));
	         this.userName.set(userInfo.data[0].userName);
         }
         
	};
	

	Model.prototype.logoutBtnClick = function(event){
		localStorage.removeItem("userInfo");
		this.isLogin.set(false);
		//console.log("user",localStorage.getItem("userInfo"));
	};
	
	
	
	
	

	
	
	
	
	Model.prototype.modelModelConstructDone = function(event){
	    if(localStorage.getItem("userInfo")){
	    	 this.isLogin.set(true);
	         var userInfo = JSON.parse(localStorage.getItem("userInfo"));
	         this.userName.set(userInfo.data[0].userName);    
	    }

	};
	
	
	
	
	

	
	
	
	
	return Model;
});